﻿using System;

namespace Fujitsu.JiraAnalysis.TrackingSystemAdapter
{
    public class TrackSystemCommunicationException : Exception
    {
        private Credentials Credentials { get; set; }
        private string CustomMessage { get; set; }
        private string InternalExceptionMessage { get; set; }

        public TrackSystemCommunicationException()
        {
            Credentials = new Credentials(); 
        }

        public TrackSystemCommunicationException(Credentials credential, string message)
        {
            Credentials = credential;
            CustomMessage = message;
        }
        public TrackSystemCommunicationException(Credentials credential, string message, string internalExceptionMessage)
            : this(credential, message)
        {
            InternalExceptionMessage = internalExceptionMessage;
        }

        public TrackSystemCommunicationException(string login, string serviceUrl, string message)
            : this(new Credentials(login, serviceUrl), message)
        {
        }

        public TrackSystemCommunicationException(string login, string serviceUrl, string message, string internalExceptionMessage)
            : this(login, serviceUrl, message)
        {
            InternalExceptionMessage = internalExceptionMessage;
        }


        public override string Message
        {
            get
            {
                var message = string.Format("{0}\nService Url: {1}. Login: {2}", CustomMessage, Credentials.ServiceUrl, Credentials.Login);
                if (!string.IsNullOrEmpty(InternalExceptionMessage))
                {
                    return string.Format("{0}\nException:{1}",message, InternalExceptionMessage);
                }

                return message;
            }
        }
    }
}
